<html>
<head>
	<title>Select a Element</title>
	<script type="text/javascript" src="/scripts/ajax.js"></script>
	<script type="text/javascript">
		var objectHTTPXML = createHTTPXMLObject()
		var getElementTemplate = "/templates/getElement.xsl"
		function loadElement(){
			if(objectHTTPXML) {
				document.getElementById("divTL").style.display = ""
				objectHTTPXML.open('GET', '/model.load.allelements?m_id=' + dialogArguments[1], true)
				objectHTTPXML.onreadystatechange = returnElement
				objectHTTPXML.send(null)
			} else {
				alert("Your browser don't suport Ajax")
			}
		}
		
		function returnElement(){
			if (objectHTTPXML.readyState == 4) {
				xml = objectHTTPXML.responseXML
				template = loadXSLfromXML(getElementTemplate, xml)
				document.getElementById("divBody").innerHTML = template
				
				var sc = document.getElementById("element")
				
				for(i = 0; i < sc.options.length; ++i){
					for(j = 0; j < dialogArguments[2].length; ++j){
						if(sc.options[i].value.split("$$$")[1] == dialogArguments[3][j]){
							sc.remove(i)
							i--
							break
						}
					}
				}
				
				document.getElementById("divTL").style.display = "none"
			}	
		}
		
		function updateParent() {
			var callerWindowObj = dialogArguments[0];
			var select = document.getElementById("element").value
			if(select == ""){
				window.close()
				return
			}
			
			var param = select.split("$$$") 
			callerWindowObj.insertElementAux(param[1], param[0])
			window.close()
		}
	
	</script>
</head>
<body>
	<div id="divTL" style="position: absolute; float: right; display: none;" width="700px">
		<table width="100">
			<tr bgcolor="red">
				<td>
					<font color="white"><strong>Receiving data...</strong></font>
				</td>
			</tr>
		</table>
	</div>
	<table width="300px">
		<tr>
			<td colspan="2">
				Select a element to be a Element
			</td>
		</tr>
		<tr>
	        <td width="35%">Class:</td>
	        <td width="65%"><div id="divBody"></div></td>
	    </tr>
	    <tr>
			<td colspan="2" align="center">
				<a href="javascript:updateParent();">OK</a> - <a href="javascript:window.close();">Cancel</a>
			</td>    	
	    </tr>
	</table>
	<script type="text/javascript">
		loadElement()
	</script>
</body>
</html>